<?php
class MY_Form_validation extends CI_Form_validation
{  
		var $input_val = array();
	 
		function __construct($config = array())
		{
		parent::__construct($config);
		 $this->CI =& get_instance();
		}
 
    /**
     * Error Array
     *
     * Returns the error messages as an array
     *
     * @return  array
     */
    function error_arrayui()
    {
        if (count($this->_error_array) === 0)
        { 
			$data = array();
			$errArr =  $this->field_arr;
			foreach($errArr as $ind=>$val){
				$data["error_".$ind] = $val; 
				if($this->input_checkbox[$ind] == 0)
					$data[$ind] = ($this->CI->input->get_post($ind) && $this->input_val[$ind] !== NULL) ?  $this->CI->input->get_post($ind) : $this->input_val[$ind]; 
				else
					$data[$ind] = ($this->CI->input->get_post($ind) && $this->input_val[$ind] !== NULL) ?  ' checked="checked" ' : (($this->input_val[$ind]) ? ' checked="checked" ':'' ); 
			}
            return $data;
        }else{ 
			$data = array();
			$errArr =  $this->field_arr;
			//$errArr =  $this->_error_array;
			foreach($errArr as $ind=>$val){
				$data["error_".$ind] = form_error($ind);
				if($this->input_checkbox[$ind] == 0)
					$data[$ind] = ($this->CI->input->get_post($ind) && $this->input_val[$ind] !== NULL) ?  $this->CI->input->get_post($ind) : $this->input_val[$ind]; 
				else
					$data[$ind] = ($this->CI->input->get_post($ind) && $this->input_val[$ind] !== NULL) ?  ' checked="checked" ' : (($this->input_val[$ind]) ? ' checked="checked" ':'' ); 
			}
            return $data;
		}
 
    }
	
	
	function set_ruless($field, $label = '', $rules = '',$filed_val=NULL,$checkbox=0)
    {
	  $this->field_arr[$field] = '';
	  $error_label = ($this->CI->lang->line($label)) ? $this->CI->lang->line($label) : $label;
      $this->set_rules($field, $error_label,  $rules);	
	  $this->input_val[$field] = $filed_val;
	  $this->input_checkbox[$field] = $checkbox;
    }
	
	
}